<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script src="jquery-3.1.1.js"></script>
    <meta name="author" content="ykf">
    <title>置顶效果</title>
    <style>
        ul,li{
            margin: 0;
            padding: 0;
        }
        .content{
            height: 1500px;
            background-color: lightblue;
        }
        .scroll{
            height: 80px;
            width: 15px;
            position: fixed;
            right: 0;
            top: 50%;
        }
        .scroll li{
            height: 40px;
            background: url(img/scroll.png) no-repeat;
            position: relative;
            list-style: none;
        }
        .scroll .bottom{
            background-position: 0 -80px;
        }
        .scroll a{
            position: absolute;
            top: 0;
            right: 0;
            text-decoration: none;
            width: 80px;
            height: 40px;
            background-color: #d34;
            text-align: center;
            line-height: 40px;
            color: white;
            border-bottom-left-radius: 20px;
            border-top-left-radius: 20px;
            opacity: 0;
        }
        .scroll .bottom a{
            background-color: #333;
        }
    </style>
</head>
<body>
    <div class="content">
        <ul class="scroll">
            <li class="top"><a href="javascript:;">返回顶部</a></li>
            <li class="bottom"><a href="javascript:;">返回底部</a></li>
        </ul>
    </div>
</body>
<html>
<script>
    $('.scroll li').hover(function(){
        $(this).find('a').stop().animate({opacity:1},'fast');
    },function(){
        $(this).find('a').stop().animate({opacity:0},'fast');
    });

    $('.scroll .top a').click(function(){
        $('html,body').animate({
            scrollTop:0,
        },800)
    });
    $('.scroll .bottom a').click(function(){
        $('html,body').animate({
            scrollTop:$(document).height()
        },800)
    })
</script>